#ifndef USERFUNCS_H
#define USERFUNCS_H

#include "../ext/map/map.h"

nefFont font;
nefTexture texture;
nefTexture texture1;
nefTexture texture2;
char buf[10] = {0};
nefLight light0;
nefBrush brush;
nefAudio audio;

baiduMapStaticImage map;
baiduMapGetPath path;

void onSetup()
{
    audio.Open("./res/mus/1.wav");
    audio.setVolume(nefMaxVolume);
    audio.Play();
    Delay_ms(1000);
    audio.Pause();
    Delay_ms(2000);
    audio.Resume();
    Delay_ms(2000);
    audio.Rewind();
    audio.Play();
    map.setImageStyle(800, 600, 11);
    map.setCentral(116.69, 23.39);
    map.getStaticImage("./res/pic/map", 10, 1);
    path.setMode(DRIVING);
    path.setOrigin("汕头大学");
    path.setDestination("汕头市金山中学");
    path.setCity("汕头", "汕头");
    path.getPath("./res/xml/path", 10, 1);

    font.Open("./res/ttf/segoeui.ttf", 50);
    font.Set(TTF_STYLE_BOLD | TTF_STYLE_ITALIC);
    texture.RenderText(font.font, "hello world", {1, 1, 1});
    texture2.LoadImage("./res/pic/map.png");
    light0.setID(nefLight_0);
    light0.setPosition(0, 0, -4, 1);
    light0.setAmbient(0, 0, 0, 0);
    light0.setDiffuse(1.0, 1.0, 1.0, 1.0);
    light0.setSpecular(1.0, 1.0, 1.0, 1.0);
    light0.turnOn();
    light0.turnOff();
}

void onLoop()
{
    sprintf(buf, "%d", int(Renderfps));
    texture1.RenderText(font.font, buf, {1, 1, 1});
}

void onHUD()
{
    brush.HUD_drawText(texture1, 50, 50);
    brush.HUD_drawText(texture, 50, 100);
    brush.HUD_drawImage(texture2, 100, 300, 200, 160);
}

void onRender()
{
    texture2.setAmbient(0, 0, 0, 1);
    texture2.setDiffuse(0.7, 0.7, 0.7, 1);
    texture2.setSpecular(0.7, 0.7, 0.7, 1);
    texture2.setEmission(0.7, 0.7, 0.7, 1);
    texture2.setShininess(30);
    texture2.Blind();
    texture2.unBlind();
    texture2.Blind();
    brush.setColor(1, 1, 1);
    brush.beginPolygon();
    brush.addNormal(0, 0, 1);
    brush.addPoint(0, 0, -5, 0, 0);
    brush.addPoint(6.5, 0, -5, 1, 0);
    brush.addPoint(6.5, 5, -5, 1, 1);
    brush.addPoint(0, 5, -5, 0, 1);
    brush.end();
}

void onExit()
{
    font.Free();
    texture.Free();
    texture1.Free();
    texture2.Free();
    audio.Free();
}

#endif